﻿Imports System.IO

Public Class BlockTwoHomeworkSectionTwo
    Dim QuestionNumber As Integer
    Dim dtmTest, dtmTest2 As Date
    Dim filename As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
    'Declare the Array as 10 rows and 3 columns
    Dim ArrayMax As Integer = 31 'One number past the end of actual info in array
    Dim HWQuestions(ArrayMax, 6) As String
    Dim intResponse As Integer
    Dim intQuestionCount As Integer = 0
    Dim intAnswerCount As Integer = 0
    Dim intReferenceCount As Integer = 0
    Dim intFirstRun As Integer = 1
    Dim strUser As String = "Enter Last Name"
    Dim strAnswer, strAnswer2, strAnswer3, strAnswer4, strAnswer5, strAnswer6, _
            strAnswer7, strAnswer8, strAnswer9, strAnswer10, strAnswer11, strAnswer12, _
            strAnswer13, strAnswer14, strAnswer15, strAnswer16, strAnswer17, _
            strAnswer18, strAnswer19, strAnswer20 As String
    Dim intChoiceACount As Integer = 2
    Dim intChoiceBCount As Integer = 3
    Dim intChoiceCCount As Integer = 4
    Dim intChoiceDCount As Integer = 5

    Shared Property MidiParent As MainForm

    Private Sub CloseToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles CloseToolStripMenuItem.Click
        Me.Close()
    End Sub

    Private Sub BlockOneAppraisals_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        txtObj.Text = "Objectives:" + vbCrLf + "- State characteristics of the AN/GRR-23 and AN/GRR-24 Receivers." _
          + vbCrLf + "- Identify the functions of the major components in a basic AM receiver overall block diagram."
        If (System.IO.File.Exists(filename & "\Homework\Block 2\Block 2 Section 2.txt")) Then
            intResponse = MsgBox("This assignment has already been completed.  Are you sure you want to delete the current assignment and reaccomplish it?", 4, "Confirm Assignment Deletion")
            If intResponse = MsgBoxResult.Yes Then
                System.IO.File.Delete(filename & "\Homework\Block 2\Block 2 Section 2.txt")
                System.IO.File.Create(filename & "\Homework\Block 2\Block 2 Section 2.txt").Dispose()
            ElseIf intResponse = MsgBoxResult.No Then
                Me.Close()
            End If
        End If
        If (Not System.IO.File.Exists(filename & "\Homework\Block 2\Block 2 Section 2.txt")) Then
            System.IO.File.Create(filename & "\Homework\Block 2\Block 2 Section 2.txt").Dispose()
        End If
        If (Not System.IO.File.Exists(filename & "\Instructor\Block 2\Block 2 Section 2.txt")) Then
            System.IO.File.Create(filename & "\Instructor\Block 2\Block 2 Section 2.txt").Dispose()
        End If
        txtReference.Visible = False 'Hides reference box
        lblReference.Visible = False ' Hides reference box
        chkboxChoiceA.Visible = False
        chkboxChoiceB.Visible = False
        chkboxChoiceC.Visible = False
        chkboxChoiceD.Visible = False
        strUser = InputBox("Please enter last name", strUser)
        If strUser Is "" Then
            Me.Close()
        End If
        '************************************************
        '****** Questions Are Loaded Here****************
        '******* Column 1 is Questions (Preloaded)*******
        '******* Column 2 is Accepts Students Answer*****
        '******* Column 3 is Reference ******************

        '*********????????**********
        HWQuestions(1, 1) = ""
        HWQuestions(1, 2) = strAnswer
        HWQuestions(1, 3) = ""

        HWQuestions(2, 1) = ""
        HWQuestions(2, 2) = strAnswer2
        HWQuestions(2, 3) = ""

        HWQuestions(3, 1) = ""
        HWQuestions(3, 2) = strAnswer3
        HWQuestions(3, 3) = "Student Workbook Page 12, Section 3"

        HWQuestions(4, 1) = ""
        HWQuestions(4, 2) = strAnswer4
        HWQuestions(4, 3) = "Student Workbook Page 12, Section 3"

        HWQuestions(5, 1) = ""
        HWQuestions(5, 2) = strAnswer5
        HWQuestions(5, 3) = "Student Workbook Page 12, Section 3"

        HWQuestions(6, 1) = ""
        HWQuestions(6, 2) = strAnswer6
        HWQuestions(6, 3) = "Student Workbook Page 12, Section 3"

        HWQuestions(7, 1) = ""
        HWQuestions(7, 2) = strAnswer7
        HWQuestions(7, 3) = "Student Workbook Page 12, Section 3"

        HWQuestions(8, 1) = ""
        HWQuestions(8, 2) = strAnswer8
        HWQuestions(8, 3) = "Student Workbook Page 12, Section 3"

        HWQuestions(9, 1) = ""
        HWQuestions(9, 2) = strAnswer9
        HWQuestions(9, 3) = "Student Workbook Page 12, Section 3"

        HWQuestions(10, 1) = ""
        HWQuestions(10, 2) = strAnswer10
        HWQuestions(10, 3) = "Student Workbook Page 12, Section 3"

        HWQuestions(11, 1) = ""
        HWQuestions(11, 2) = strAnswer11
        HWQuestions(11, 3) = "Student Workbook Page 12, Section 3"

        HWQuestions(12, 1) = ""
        HWQuestions(12, 2) = strAnswer12
        HWQuestions(12, 3) = "Student Workbook Page 12, Section 3"

        HWQuestions(13, 1) = ""
        HWQuestions(13, 2) = strAnswer13
        HWQuestions(13, 3) = "Student Workbook Page 12, Section 3"

        HWQuestions(14, 1) = ""
        HWQuestions(14, 2) = strAnswer14
        HWQuestions(14, 3) = "Student Workbook Page 12, Section 3"

        HWQuestions(15, 1) = ""
        HWQuestions(15, 2) = strAnswer15
        HWQuestions(15, 3) = "Student Workbook Page 12, Section 3"

        HWQuestions(16, 1) = ""
        HWQuestions(16, 2) = strAnswer16
        HWQuestions(16, 3) = "Student Workbook Page 12, Section 3"

        HWQuestions(17, 1) = ""
        HWQuestions(17, 2) = strAnswer17
        HWQuestions(17, 3) = "Student Workbook Page 12, Section 3"

        HWQuestions(18, 1) = ""
        HWQuestions(18, 2) = strAnswer18
        HWQuestions(18, 3) = "Student Workbook Page 12, Section 3"

        HWQuestions(19, 1) = ""
        HWQuestions(19, 2) = strAnswer19
        HWQuestions(19, 3) = "Student Workbook Page 12, Section 3"

        HWQuestions(20, 1) = ""
        HWQuestions(20, 2) = strAnswer20
        HWQuestions(20, 3) = "Student Workbook Page 12, Section 3"

        '*********????????**********
        HWQuestions(21, 1) = ""
        HWQuestions(21, 2) = ""
        HWQuestions(21, 4) = ""
        HWQuestions(21, 5) = ""
        HWQuestions(21, 6) = ""
        HWQuestions(21, 3) = "Student Workbook Page 12, Section 3"

        HWQuestions(22, 1) = ""
        HWQuestions(22, 2) = ""
        HWQuestions(22, 4) = ""
        HWQuestions(22, 5) = ""
        HWQuestions(22, 6) = ""
        HWQuestions(22, 3) = "Student Workbook Page 12, Section 3"

        HWQuestions(23, 1) = ""
        HWQuestions(23, 2) = ""
        HWQuestions(23, 4) = ""
        HWQuestions(23, 5) = ""
        HWQuestions(23, 6) = ""
        HWQuestions(23, 3) = "Student Workbook Page 12, Section 3"

        HWQuestions(24, 1) = ""
        HWQuestions(24, 2) = ""
        HWQuestions(24, 4) = ""
        HWQuestions(24, 5) = ""
        HWQuestions(24, 6) = ""
        HWQuestions(24, 3) = "Student Workbook Page 12, Section 3"

        HWQuestions(25, 1) = ""
        HWQuestions(25, 2) = ""
        HWQuestions(25, 4) = ""
        HWQuestions(25, 5) = ""
        HWQuestions(25, 6) = ""
        HWQuestions(25, 3) = "Student Workbook Page 12, Section 3"

        HWQuestions(26, 1) = ""
        HWQuestions(26, 2) = ""
        HWQuestions(26, 4) = ""
        HWQuestions(26, 5) = ""
        HWQuestions(26, 6) = ""
        HWQuestions(26, 3) = "Student Workbook Page 12, Section 3"

        HWQuestions(27, 1) = ""
        HWQuestions(27, 2) = ""
        HWQuestions(27, 4) = ""
        HWQuestions(27, 5) = ""
        HWQuestions(27, 6) = ""
        HWQuestions(27, 3) = "Student Workbook Page 12, Section 3"

        HWQuestions(28, 1) = ""
        HWQuestions(28, 2) = ""
        HWQuestions(28, 4) = ""
        HWQuestions(28, 5) = ""
        HWQuestions(28, 6) = ""
        HWQuestions(28, 3) = "Student Workbook Page 12, Section 3"

        HWQuestions(29, 1) = ""
        HWQuestions(29, 2) = ""
        HWQuestions(29, 4) = ""
        HWQuestions(29, 5) = ""
        HWQuestions(29, 6) = ""
        HWQuestions(29, 3) = "Student Workbook Page 12, Section 3"

        HWQuestions(30, 1) = ""
        HWQuestions(30, 2) = ""
        HWQuestions(30, 4) = ""
        HWQuestions(30, 5) = ""
        HWQuestions(30, 6) = ""
        HWQuestions(30, 3) = "Student Workbook Page 12, Section 3"

        HWQuestions(31, 1) = "Close?"

        Next_Question(HWQuestions)
    End Sub

    Private Sub btnNextQuestion_Click(sender As System.Object, e As System.EventArgs) Handles btnNextQuestion.Click
        Next_Question(HWQuestions)
    End Sub

    Private Sub Clear_Display()
        txtQuestion.Clear()
        txtAnswer.Clear()
    End Sub

    Private Sub Clear_MultipleDisplay()
        txtQuestion.Clear()
        txtChoiceA.Clear()
        txtChoiceB.Clear()
        txtChoiceC.Clear()
        txtChoiceD.Clear()
    End Sub
    Private Sub LabelChange()
        If intQuestionCount = 1 Then
            Label1.Text = "Charcteristics of the AM Receiver"
        ElseIf intQuestionCount = 21 Then
            Label1.Text = "Block Diagram of the AM Reciver"
        End If
    End Sub

    Public Function Next_Question(HWQuestions As String(,))
        If intQuestionCount > 0 Then
            WriteToFile()
        End If
        If btnNextQuestion.Text = "Done" Then
            Me.Close()
            OpenResults()
        End If
        intQuestionCount = intQuestionCount + 1
        If intQuestionCount = 30 Then
            btnNextQuestion.Text = "Done"
        End If
        LabelChange()
        If intQuestionCount >= 21 Then
            txtAnswer.Visible = False
            lblAnswer.Visible = False
            txtChoiceA.Visible = True
            txtChoiceB.Visible = True
            txtChoiceC.Visible = True
            txtChoiceD.Visible = True
            lblChoiceA.Visible = True
            lblChoiceB.Visible = True
            lblChoiceC.Visible = True
            lblChoiceD.Visible = True
            chkboxChoiceA.Visible = True
            chkboxChoiceB.Visible = True
            chkboxChoiceC.Visible = True
            chkboxChoiceD.Visible = True

            txtQuestion.Text = HWQuestions(intQuestionCount, 1)
            txtChoiceA.Text = HWQuestions(intQuestionCount, 2)
            txtChoiceB.Text = HWQuestions(intQuestionCount, 4)
            txtChoiceC.Text = HWQuestions(intQuestionCount, 5)
            txtChoiceD.Text = HWQuestions(intQuestionCount, 6)

        ElseIf intQuestionCount >= 0 & intQuestionCount <= 20 Then
            txtAnswer.Visible = True
            lblAnswer.Visible = True
            txtChoiceA.Visible = False
            txtChoiceB.Visible = False
            txtChoiceC.Visible = False
            txtChoiceD.Visible = False
            lblChoiceA.Visible = False
            lblChoiceB.Visible = False
            lblChoiceC.Visible = False
            lblChoiceD.Visible = False
            chkboxChoiceA.Visible = False
            chkboxChoiceB.Visible = False
            chkboxChoiceC.Visible = False
            chkboxChoiceD.Visible = False

            txtQuestion.Text = HWQuestions(intQuestionCount, 1)
            intAnswerCount = intAnswerCount + 1
            HWQuestions(intAnswerCount, 2) = txtAnswer.Text
            intReferenceCount = intReferenceCount + 1
            txtReference.Text = HWQuestions(intReferenceCount, 3)
            txtAnswer.Focus()
        End If
        Return intQuestionCount & intAnswerCount
    End Function

    Private Sub WriteToFile()
        Dim Integrity As String = (filename & "\Instructor\Block 2\Block 2 Section 2.txt")
        Dim Results As String = (filename & "\Homework\Block 2\Block 2 Section 2.txt")

        '***********Output to hidden file for Instructor Check***********
        If System.IO.File.Exists(Integrity) = True Then
            Dim hiddenWriter As New System.IO.StreamWriter(Integrity, True)
            If intQuestionCount = 1 Then
                hiddenWriter.WriteLine("- " & txtObj.Text)
                hiddenWriter.WriteLine()
                hiddenWriter.WriteLine("Student: " & strUser)
                hiddenWriter.WriteLine()
                hiddenWriter.WriteLine("Date: " & (DateValue(Now)))
                hiddenWriter.WriteLine("Time: " & (TimeValue(Now)))
            End If
            If intQuestionCount = 1 Or intQuestionCount = 21 Then
                hiddenWriter.WriteLine(Label1.Text)
            End If
            hiddenWriter.WriteLine("Question: " & txtQuestion.Text)
            If intQuestionCount >= 21 Then
                If chkboxChoiceA.CheckState = 1 Then
                    hiddenWriter.WriteLine("Answer:  A: " & txtChoiceA.Text)
                ElseIf chkboxChoiceB.CheckState = 1 Then
                    hiddenWriter.WriteLine("Answer:  B: " & txtChoiceB.Text)
                ElseIf chkboxChoiceC.CheckState = 1 Then
                    hiddenWriter.WriteLine("Answer:  C: " & txtChoiceC.Text)
                ElseIf chkboxChoiceD.CheckState = 1 Then
                    hiddenWriter.WriteLine("Answer:  D: " & txtChoiceD.Text)
                End If
                hiddenWriter.WriteLine("Reference: " & txtReference.Text)
                hiddenWriter.WriteLine()
            End If
            If chkboxChoiceA.Visible = False Then
                hiddenWriter.WriteLine("Answer:" & txtAnswer.Text)
                hiddenWriter.WriteLine("Reference: " & txtReference.Text)
                hiddenWriter.WriteLine()
            End If
            If intQuestionCount = 30 Then
                hiddenWriter.WriteLine("Block 2 Section 2 Homework Complete")
                hiddenWriter.WriteLine("Date: " & (DateValue(Now)))
                hiddenWriter.WriteLine("Time: " & (TimeValue(Now)))
            End If
            hiddenWriter.Close()
        Else
            MsgBox("File Does Not Exist PRIVATE")
        End If

        '******Output to file for Student to review***********
        If System.IO.File.Exists(Results) = True Then
            Dim hiddenWriter As New System.IO.StreamWriter(Results, True)
            If intQuestionCount = 1 Then
                hiddenWriter.WriteLine("- " & txtObj.Text)
                hiddenWriter.WriteLine()
                hiddenWriter.WriteLine("Student: " & strUser)
                hiddenWriter.WriteLine()
                'hiddenWriter.WriteLine("Date: " & (DateValue(Now)))
                'hiddenWriter.WriteLine("Time: " & (TimeValue(Now)))
            End If
            If intQuestionCount = 1 Or intQuestionCount = 21 Then
                hiddenWriter.WriteLine(Label1.Text)
            End If
            hiddenWriter.WriteLine("Question: " & txtQuestion.Text)
            If intQuestionCount >= 21 Then
                If chkboxChoiceA.CheckState = 1 Then
                    hiddenWriter.WriteLine("Answer:  A: " & txtChoiceA.Text)
                ElseIf chkboxChoiceB.CheckState = 1 Then
                    hiddenWriter.WriteLine("Answer:  B: " & txtChoiceB.Text)
                ElseIf chkboxChoiceC.CheckState = 1 Then
                    hiddenWriter.WriteLine("Answer:  C: " & txtChoiceC.Text)
                ElseIf chkboxChoiceD.CheckState = 1 Then
                    hiddenWriter.WriteLine("Answer:  D: " & txtChoiceD.Text)
                End If
                hiddenWriter.WriteLine()
            End If
            If chkboxChoiceA.Visible = False Then
                hiddenWriter.WriteLine("Answer:" & txtAnswer.Text)
                hiddenWriter.WriteLine()
            End If
            If intQuestionCount = 30 Then
                hiddenWriter.WriteLine("Block 2 Section 2 Homework Complete")
                'hiddenWriter.WriteLine("Date: " & (DateValue(Now)))
                'hiddenWriter.WriteLine("Time: " & (TimeValue(Now)))
            End If
            hiddenWriter.Close()
        Else
            MsgBox("File Does Not Exist")
        End If
        If intQuestionCount > 0 Then
            txtAnswer.Clear()
            chkboxChoiceA.CheckState = CheckState.Unchecked
            chkboxChoiceB.CheckState = CheckState.Unchecked
            chkboxChoiceC.CheckState = CheckState.Unchecked
            chkboxChoiceD.CheckState = CheckState.Unchecked
        End If
    End Sub

    Private Sub OpenResults()
        Dim p As Process = Process.Start(filename & "\Homework\Block 2\Block 2 Section 2.txt")
    End Sub
End Class